# coding: utf-8
# @Author : lryself
# @Date : 2020/12/18 1:18
# @Software: PyCharm
from flask_login import LoginManager
from ..models.UserMinModel import UserMin

login_manager = LoginManager()


def init_loginManager(app):
    login_manager.login_view = 'views.login'
    login_manager.login_message_category = 'info'
    login_manager.login_message = '请登录！'
    login_manager.init_app(app)


@login_manager.user_loader
def loader_user(user_id):
    result_dict = UserMin.get(user_id)
    if result_dict.get("code") == '200':
        return result_dict.get("data")
    return None
